#include "store/store.h"
#include "buffer.h"


struct cache* cache_build(size_t buffer_size){
	size_t cache_size=sizeof(struct cache);
	struct cache *cc=(struct cache*)malloc(cache_size);

	struct bufferFactory *hdl = bufferFactory_build(buffer_size,CACHE_BUFFER_COUNT);
	if(hdl==NULL){
		return NULL;	
	}
	cc->bf_hdl=hdl;
	
	int i=0;
	for(;i < CACHE_BUFFER_COUNT;i++){
	//TODO useage of cache
		(cc->data_arr)[i]=buffer_new(cc->bf_hdl);	
	}
	cc->rd_index=0;
	cc->wr_index=0;
	cc->buffer_size=CACHE_BUFFER_COUNT;	
	return cc;
}

int cache_release(struct cache *cc){
	int i=0;
	for(;i < CACHE_BUFFER_COUNT;i++){
		buffer_del(cc->bf_hdl,(cc->data_arr)[i]);
	}
	free(cc);
	return 0;
}
